]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
theme-node: Add lookup_url/get_url() methods
authorFlorian Müllner <fmuellner@gnome.org>
Tue, 16 Apr 2013 12:43:51 +0000 (14:43 +0200)
committerFlorian Müllner <fmuellner@gnome.org>
Tue, 16 Apr 2013 17:10:40 +0000 (19:10 +0200)
Similar to the existing generic getter methods, add lookup functions
for URL properties like the standard background-image/border-image
properties.

https://bugzilla.gnome.org/show_bug.cgi?id=693688

src/st/st-theme-node.c
src/st/st-theme-node.h

index 8e2e7b7737a9a4f6c1344818376971c9a01ab1f7..db6b023b4e9aac336f5cab38aaaf240afd90faa5 100644 (file)
@@ -879,6 +879,101 @@ st_theme_node_get_double (StThemeNode *node,
     }
 }
 
+/**
+ * st_theme_node_lookup_url:
+ * @node: a #StThemeNode
+ * @property_name: The name of the string property
+ * @inherit: if %TRUE, if a value is not found for the property on the
+ *   node, then it will be looked up on the parent node, and then on the
+ *   parent's parent, and so forth. Note that if the property has a
+ *   value of 'inherit' it will be inherited even if %FALSE is passed
+ *   in for @inherit; this only affects the default behavior for inheritance.
+ * @value: (out): location to store the newly allocated value that was
+ *   determined. If the property is not found, the value in this location
+ *   will not be changed.
+ *
+ * Looks up a property containing a single URL value.
+ *
+ * See also st_theme_node_get_url(), which provides a simpler API.
+ *
+ * Return value: %TRUE if the property was found in the properties for this
+ *  theme node (or in the properties of parent nodes when inheriting.)
+ */
+gboolean
+st_theme_node_lookup_url (StThemeNode  *node,
+                          const char   *property_name,
+                          gboolean      inherit,
+                          char        **value)
+{
+  gboolean result = FALSE;
+  int i;
+
+  ensure_properties (node);
+
+  for (i = node->n_properties - 1; i >= 0; i--)
+    {
+      CRDeclaration *decl = node->properties[i];
+
+      if (strcmp (decl->property->stryng->str, property_name) == 0)
+        {
+          CRTerm *term = decl->value;
+          CRStyleSheet *base_stylesheet;
+          GFile *file;
+
+          if (term->type != TERM_URI && term->type != TERM_STRING)
+            continue;
+
+          if (decl->parent_statement != NULL)
+            base_stylesheet = decl->parent_statement->parent_sheet;
+          else
+            base_stylesheet = NULL;
+
+          file = _st_theme_resolve_url (node->theme,
+                                        base_stylesheet,
+                                        decl->value->content.str->stryng->str);
+          *value = g_file_get_path (file);
+          g_object_unref (file);
+          result = TRUE;
+          break;
+        }
+    }
+
+  if (!result && inherit && node->parent_node)
+    result = st_theme_node_lookup_url (node->parent_node, property_name, inherit, value);
+
+  return result;
+}
+
+/*
+ * st_theme_node_get_url:
+ * @node: a #StThemeNode
+ * @property_name: The name of the string property
+ *
+ * Looks up a property containing a single URL value.
+ *
+ * See also st_theme_node_lookup_url(), which provides more options,
+ * and lets you handle the case where the theme does not specify the
+ * indicated value.
+ *
+ * Return value: the newly allocated value if found.
+ *  If @property_name is not found, a warning will be logged and %NULL
+ *  will be returned.
+ */
+char *
+st_theme_node_get_url (StThemeNode *node,
+                       const char  *property_name)
+{
+  char *value;
+
+  if (st_theme_node_lookup_url (node, property_name, FALSE, &value))
+    return value;
+  else
+    {
+      g_warning ("Did not find string property '%s'", property_name);
+      return NULL;
+    }
+}
+
 static const PangoFontDescription *
 get_parent_font (StThemeNode *node)
 {
index 98da358ba3c90bb8420c21f391e924978ada986c..4a5f58c46e1cb1b6df6ad0eb19fca44e3ab6ce51 100644 (file)
@@ -142,6 +142,10 @@ gboolean st_theme_node_lookup_shadow (StThemeNode  *node,
                                       const char   *property_name,
                                       gboolean      inherit,
                                       StShadow    **shadow);
+gboolean st_theme_node_lookup_url    (StThemeNode  *node,
+                                      const char   *property_name,
+                                      gboolean      inherit,
+                                      char        **value);
 
 /* Easier-to-use variants of the above, for application-level use */
 void          st_theme_node_get_color  (StThemeNode  *node,
@@ -153,6 +157,8 @@ gdouble       st_theme_node_get_length (StThemeNode  *node,
                                         const char   *property_name);
 StShadow     *st_theme_node_get_shadow (StThemeNode  *node,
                                         const char   *property_name);
+char         *st_theme_node_get_url    (StThemeNode  *node,
+                                        const char   *property_name);
 
 /* Specific getters for particular properties: cached
  */